import pyOsi

#Create a problem pointer.  We use the base class here.
theSI = pyOsi.getOsi("MSK")
if not theSI:
    exit(-1)

#Read in an mps file.  This one's from the MIPLIB library.
#si->readMps("../../Data/Sample/p0033");
if theSI.readMps("p0033") > 0:
    exit(-1)

#Solve the (relaxation of the) problem
theSI.initialSolve()

#Check the solution
if ( theSI.isProvenOptimal() ):
    print "Found optimal solution!" 
    print "Objective value is %f" % theSI.getObjValue()
    n = theSI.getNumCols()
    solution = theSI.getColSolution()
    for i in solution:
        print i
    if abs(theSI.getObjValue() - 2520.571739) > 0.000001:
            exit(-1)
else: 
    print "Didn't find optimal solution."
    exit(-1)

if theSI.hasChangeCoeffs:
    print "the Solver has a ChangeCoeff method"
    rows = pyOsi.Int_array(1)
    rows[0] = 0
    cols = pyOsi.Int_array(1)
    cols[0] = 1
    vals = pyOsi.Double_array(1)
    vals[0] = 2.00
    theSI.changeCoeffs(rows,cols,vals)
    theSI.writeMps("cambio")
    theSI.resolve()
    if ( theSI.isProvenOptimal() ):
        print "Found optimal solution!" 
        print "Objective value is %f" % theSI.getObjValue()
        if abs(theSI.getObjValue() - 2622.571739) > 0.000001: exit(-1)
    else:
        print "Didn't find optimal solution."
        exit(-1)	 
else:
    print "the Solver has not a ChangeCoeff method"
    exit(-1)

theOtheSI = pyOsi.getOsi('CLP')
try:
    theOtheSI.changeCoeffs(rows,cols,vals)
except RuntimeError, text:
    print text
except :
    print "Unexpected exception"
    exit(-1)

